package com.baishui.gateway.handler;

import com.baishui.gateway.context.GateWayRouteContext;
import com.baishui.gateway.response.ResponseProcesser;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class BaseHandler implements Handler<RoutingContext> {

    protected Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ResponseProcesser responseProcesser;


    public void writeResponse(RoutingContext routingContext, GateWayRouteContext context) {

        responseProcesser.writeImage();

        responseProcesser.writeSimple();

    }

    public void writeError(RoutingContext routingContext) {
        Throwable failure = routingContext.failure();
        HttpServerResponse response = routingContext.response();
        response.putHeader("content-type", "text/plain")
                .end("writeError !");

    }

}
